﻿#region 程序集引用
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Configuration;
#endregion

#region 版权注释
/*===========================================================================
// Copyright (C) 2016 seabay.cn，并保留所有 
// 作者：吴岸标 QQ:405403610
// 创建日期：2016-06-05
// 功能描述： 列表页基类 Controller
===========================================================================*/
#endregion

namespace Zhang
{
    namespace AdminPage
    {
        /// <summary>
        /// 平台后台基类 Controller
        /// </summary>
        public partial class BaseController : System.Web.Mvc.Controller
        {
            /// <summary>
            /// 分页大小
            /// </summary>
            private int _pageSize = 0;
            /// <summary>
            /// 当前页码
            /// </summary>
            private int _pageIndex = 0;
            /// <summary>
            /// 不传送到编辑页的URL参数
            /// </summary>
            private static readonly string FilterUrlParamKey = "||pg||rsCount||rnd||pgSize||";

            /// <summary>
            /// 需传递的URL参数
            /// </summary>
            protected string UrlParam
            {
                get
                {
                    string urlParam;

                    urlParam = string.Empty;

                    foreach (string key in Request.QueryString.Keys)
                    {
                        if (FilterUrlParamKey.IndexOf(key) < 0)
                        {
                            if (!string.IsNullOrEmpty(urlParam))
                            {
                                urlParam += "&";
                            }

                            urlParam += key + "=" + Request.QueryString[key];
                        }
                    }

                    urlParam = Server.UrlEncode(urlParam);

                    return urlParam;
                }
            }

            /// <summary>
            /// 当前请求的分页页码,可为 Null
            /// </summary>
            protected int PageIndex
            {
                get { return this._pageIndex; }
            }

            /// <summary>
            /// 分页大小
            /// </summary>
            protected int PageSize
            {
                get
                {
                    this._pageSize = this._pageSize == 0 ? int.Parse(ConfigurationManager.AppSettings["ListPageSize"]) : this._pageSize;
                    return this._pageSize;
                }
                set { this._pageSize = value; }
            }

            /// <summary>
            /// 当前查询条件的总记录数,第一次查询或是第一页请求时为 Null
            /// </summary>
            protected int TotalRecord = 0;

            /// <summary>
            /// 获取排序
            /// </summary>
            /// <returns></returns>
            protected Model.Sequence Sequence
            {
                get { return GetSeq(); }

            }

            // 获取排序
            Model.Sequence GetSeq()
            {
                Model.Sequence model;
                string seq, fieldName;

                seq = Request.QueryString["abshop_sort"];
                fieldName = Request.QueryString["abshop_filedname"];
                model = null;

                if (!string.IsNullOrEmpty(seq) && !string.IsNullOrEmpty(fieldName))
                {
                    model = new Model.Sequence();
                    seq = seq.Trim();
                    model.FieldName = fieldName.Trim();

                    switch (seq)
                    {
                        case "1":       // 升序
                            model.SeqType = Model.SequenceType.Asc;
                            break;
                        case "2":       // 降序 
                            model.SeqType = Model.SequenceType.Desc;
                            break;
                        default:
                            model = null;
                            break;
                    }

                }

                return model;
            }


        }
    }
}
